<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="订单号" prop="AlbaranProveedorNo">
        <el-input @focus="getInputFocus($event)"  ref="inputText"
    clearable v-model="queryParams.AlbaranProveedorNo" placeholder="请输入订单号"   
          clearable style="width: 200px" @keyup.enter.native="handleQuery"  />
      </el-form-item>
	  <el-form-item label="审核状态" prop="Bloqueado">
	    <el-select v-model="queryParams.Bloqueado" placeholder="请选择审核状态" style="width: 150px">
			<el-option  v-for="item in stgj" :label="item.label" :value="item.value" ></el-option>
	    </el-select>
	  </el-form-item>
	  
	  <el-form-item label="月份" prop="Bloqueado">
	    <el-input v-model="queryParams.month" placeholder="请输入月份" clearable
	      style="width: 150px" @keyup.enter.native="month" />
	  </el-form-item>
		<el-form-item>
			<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <!-- <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> -->
		</el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
		<el-col :span="1.5">
			<el-button type="primary"  plain  icon="el-icon-plus" size="mini"  @click="handleAdd" >新增</el-button>
		</el-col>
		<el-col :span="1.5">
			<el-button type="success" plain icon="el-icon-edit" size="mini" @click="handleShezhi" >设置</el-button>
		</el-col>
		<el-col :span="1.5">
			<el-upload  action="#" :show-file-list="false" :auto-upload="false" :on-change="importPhone">
				<el-button  plain icon="el-icon-download" type="warning" size="mini">导入</el-button>
			</el-upload>
		</el-col> 
		<el-col :span="1.5">
			<div style="    font-size: 14px; padding: 4px;  margin-left: 38px;  color: #a8a8a8;">
			供应商：<el-select  value-key="shezhighs"  v-model="shezhighs" @change="searchSelect" placeholder="请选择供应商">
			<el-option v-for="item in style1" :key="item.id" :label="item.nombreES" :value="item.nombreES"></el-option>
			</el-select>
			&nbsp;&nbsp;类别：{{shezhitype}}&nbsp;&nbsp;进价倍数：{{shezhinum}}&nbsp;&nbsp;价格尾数：{{shezhilastnum}}&nbsp;&nbsp;现(进价/售价)计算比例：{{shezhichajia}}
			&nbsp;&nbsp;是否更新销售价：
			<span v-if="shezhiisupdate == 1">是</span>
			<span v-if="shezhiisupdate == 2">否</span>
			</div>
	   </el-col> 
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="roleList" @selection-change="handleSelectionChange">
		<el-table-column label="订单号" prop="albaranProveedorNo" align="center" />
		<el-table-column label="供应商名称" prop="proveedorID" :show-overflow-tooltip="true"  align="center" />
		<el-table-column label="数量" prop="precioUsado" :show-overflow-tooltip="true"  align="center" />
		<el-table-column label="单据总额" prop="total" :show-overflow-tooltip="true"  align="center" />
		<el-table-column label="审核状态" prop="bloqueado" :show-overflow-tooltip="true"  align="center" >
			<template slot-scope="scope">
				<span v-if="scope.row.bloqueado == 0" style="color:red">未审核</span>
				<span v-if="scope.row.bloqueado == 1">已审核</span>
			</template>
		</el-table-column>
		<!-- <el-table-column label="职员" prop="operadorID" :show-overflow-tooltip="true"  align="center" />
		<el-table-column label="审核员" prop="verificadorID" :show-overflow-tooltip="true"  align="center" /> -->
		<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
			<template slot-scope="scope" v-if="scope.row.roleId !== 1">
				<el-button size="mini" type="text" icon="el-icon-edit" @click="handleAudit(scope.row)" >审核</el-button>
				<el-button size="mini" type="text" icon="el-icon-edit" @click="handleduihuo(scope.row)" >对货</el-button>
				<el-button size="mini" type="text" icon="el-icon-delete" @click="handleshanchu(scope.row)" >删除</el-button>
			</template>
		</el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
    :limit.sync="queryParams.pageSize" @pagination="getList" />
    <el-dialog :title="title" :visible.sync="open" width="1200px" >
		<el-button type="primary" icon="el-icon-edit" size="mini" style="margin-bottom: 15px;" @click="handleAddwwd">添加(F9)</el-button>
			<el-table :data="dataListpush" size="mini" stripe highlight-current-row >
				<el-table-column type="index" label="序号" width="50"></el-table-column>
				<el-table-column prop="articuloID" label="商品编码" :show-overflow-tooltip="true" align="center" >
					<template slot-scope="scope">
						<el-input v-model.trim="scope.row.articuloID" @keyup.enter.native="handleQueryBianHao(scope.$index)" :id="'sysBianmaInput_xx' + scope.$index"  @blur="handlerBianmaTianJia(scope.$index,scope.row)" placeholder="商品编码" clearable></el-input>
					</template>
				</el-table-column>
				<el-table-column prop="codigoBarra" label="商品条码" :show-overflow-tooltip="true" align="center">
					<template slot-scope="scope">
						<el-input v-model.trim="scope.row.codigoBarra" @keyup.enter.native="handleQueryTiaoMa(scope.$index)" :id="'sysTiaomaInput_xx' + scope.$index"  placeholder="商品条码" clearable></el-input>
					</template>
				</el-table-column>
				<el-table-column prop="nombreES" label="商品名称" :show-overflow-tooltip="true" align="center">
					<template slot-scope="scope">
						<el-input v-model.trim="scope.row.nombreES" @keyup.enter.native="handleQueryMingCheng(scope.$index)" :id="'sysMingchengInput_xx' + scope.$index"  placeholder="商品名称" clearable></el-input>
					</template>
				</el-table-column>
				<el-table-column prop="precio" label="进价" :show-overflow-tooltip="true" align="center">
					<template slot-scope="scope">
						<el-input v-model.trim="scope.row.precio" @keyup.enter.native="handleQueryJinJia(scope.$index)" :id="'sysJinjiaInput_xx' + scope.$index"  placeholder="进价" clearable></el-input>
					</template>
				</el-table-column>
				<el-table-column prop="precio" label="售价" :show-overflow-tooltip="true" align="center">
					<template slot-scope="scope">
						<el-input v-model.trim="scope.row.iVA" @keyup.enter.native="handleQueryShouJia(scope.$index)" :id="'sysShoujiaInput_xx' + scope.$index"  placeholder="售价" clearable></el-input>
					</template>
				</el-table-column>
				<el-table-column prop="cantidad" label="数量"  :show-overflow-tooltip="true" align="center">
					<template slot-scope="scope">
						<el-input v-model.trim="scope.row.cantidad" @keyup.enter.native="handleQueryShuLiang(scope.$index)"  :id="'sysShuliangInput_xx' + scope.$index"  placeholder="数量" clearable></el-input>
					</template>
				</el-table-column>
				<el-table-column  label="操作"  align="center" class-name="small-padding fixed-width">
				    <template slot-scope="scope">
				        <el-button type="text" icon="el-icon-delete"  @click="handleDeletewpq(scope.$index, scope.row)">删除</el-button>
				    </template>
				</el-table-column>
			</el-table>  
		<div slot="footer" class="dialog-footer">
			<el-button type="primary" @click="submitForm">提 交</el-button>
			<el-button @click="cancel">取 消</el-button>
		</div>
    </el-dialog>
	
	<el-dialog :title="title" :visible.sync="openDataScope" width="500px" append-to-body>
		<el-form  ref="form" :model="form" label-width="100px">
			<el-form-item label="审核代码" prop="shenhedaima">
				<el-input v-model="form.shenhedaima" placeholder="请输入审核代码"  style="width: 150px" />
			</el-form-item>
		</el-form>
		<div slot="footer" class="dialog-footer">
			<el-button type="primary" @click="submitDataScope">审核通过</el-button>
			<el-button @click="cancelDataScope">取 消</el-button>
		</div>
	</el-dialog>
	
	<el-dialog :title="title" :visible.sync="openDataScopeShanChu" width="500px" append-to-body>
		<el-form  ref="form" :model="form" label-width="100px">
			<el-form-item label="删除代码" prop="shanchudaima">
				<el-input v-model="form.shanchudaima" placeholder="请输入删除代码"  style="width: 150px" />
			</el-form-item>
		</el-form>
		<div slot="footer" class="dialog-footer">
			<el-button type="primary" @click="submitDataScopeShanChu">删除</el-button>
			<el-button @click="cancelDataScopeShanChu">取 消</el-button>
		</div>
	</el-dialog>
	
	<el-dialog :title="title" :visible.sync="openshezhi" width="500px" append-to-body>
		<el-form ref="form" :model="form"  label-width="170px">
			<el-form-item label="供应商" prop="ghs">
				<el-select v-model="form.ghs" placeholder="请选择供应商" style="width: 250px">
					<el-option v-for="item in style1" :key="item.id" :label="item.nombreES" :value="item.nombreES" ></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="类别" prop="type">
				<el-select v-model="form.type" placeholder="请选择类别" style="width: 250px">
					<el-option v-for="item in style2" :label="item.nombreES" :value="item.nombreES" ></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="进价倍数">
				<el-input v-model="form.num" placeholder="请输入进价倍数" style="width: 250px"></el-input>
			</el-form-item>
			<el-form-item label="价格尾数">
				<el-input v-model="form.lastnum" placeholder="请输入价格尾数" style="width: 250px"></el-input>
			</el-form-item>
			<el-form-item label="现(进价/售价)计算比例">
				<el-input v-model="form.zhek" placeholder="请输入现(进价/售价)计算比例" style="width: 250px"></el-input>
			</el-form-item>
			<el-form-item label="是否更新销售价" prop="isupdate">
				<el-select v-model="selectedValue"  placeholder="请选择是否更新销售价" style="width: 250px">
					<el-option   v-for="item in isupxiaoshou"  :key="item.value" :label="item.label" :value="item.value" >
					</el-option>
				</el-select>
			</el-form-item>
		</el-form>
		<div slot="footer" class="dialog-footer">
			<el-button type="primary" @click="submitShezhi">确 定</el-button>
			<el-button @click="cancelshezhi">取 消</el-button>
		</div>
	</el-dialog>
	
	<el-dialog :title="title" :visible.sync="openDataDingdan" width="1400px" append-to-body border >
		<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
			<el-form-item label="商品编码/商品条码" prop="articuloID">
				<el-input :id="'sysshangpinbianma'" v-model="queryParams2.articuloID" placeholder="请输入商品编码"
				clearable style="width: 150px" @keyup.enter.native="handleQuery1122" />
			</el-form-item>
			<el-form-item label="差数" prop="difference">
				<el-select v-model="queryParams2.difference" placeholder="请选择差数" style="width: 150px">
					<el-option  v-for="item in ischashu" :label="item.label" :value="item.value" ></el-option>
				</el-select>
				<!-- <el-input v-model="queryParams.difference" placeholder="请输入差数"
				clearable style="width: 120px" @keyup.enter.native="handleQuery1122" /> -->
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery1122" >搜索</el-button>
				<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAddyiyoushuju" >新增(F9)</el-button>
				<el-button type="success" plain icon="el-icon-edit" size="mini"
				v-if="openDataQuehuo"  @click="handleQueHuo" >缺货反冲</el-button>
				<el-button type="success" plain v-if="openDataDuiHuo" 
				icon="el-icon-edit" size="mini" @click="handleDuihuoAll" >一键对货</el-button>
				<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport()" >导出缺货商品信息</el-button>
			</el-form-item>
		</el-form>
		<el-table v-loading="loading" :data="roleList33">
			<el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
			<el-table-column label="商品编码" prop="articuloID" :show-overflow-tooltip="true"  align="center">
				<template slot-scope="scope">
					<span v-if="scope.row.id != ''">{{ scope.row.articuloID }}</span>
					<span v-if="scope.row.id == ''">
					<el-input :id="'sysBianmaInput_' + scope.$index" @keyup.enter.native="handleQueryBianHaoXX1(scope.$index)"  @blur="handlerBianma(scope.$index,scope.row)" v-model="scope.row.articuloID" placeholder="请输入"></el-input>
					</span>
				</template>
			</el-table-column>
			<el-table-column label="商品条码" prop="codigoBarra" :show-overflow-tooltip="true"  align="center" >
				<template slot-scope="scope">
					<span v-if="scope.row.id != ''">{{ scope.row.codigoBarra }}</span>
					<span v-if="scope.row.id == ''">
						<el-input :id="'sysTiaomaInput_' + scope.$index" @keyup.enter.native="handleQueryBianHaoXX2(scope.$index)" v-model="scope.row.codigoBarra" placeholder="请输入"></el-input>
					</span>
				</template>
			</el-table-column>
			<el-table-column label="商品名称" prop="nombreES" :show-overflow-tooltip="true"  align="center"  style="width: 200px">
				<template slot-scope="scope">
					<span v-if="scope.row.id != ''">{{ scope.row.nombreES }}</span>
					<span v-if="scope.row.id == ''">
					<el-input :id="'sysMingchengInput_' + scope.$index" @keyup.enter.native="handleQueryBianHaoXX3(scope.$index)" v-model="scope.row.nombreES" placeholder="请输入"></el-input>
					</span>
				</template>
			</el-table-column>
			<el-table-column label="原进价" prop="precioCoste" :show-overflow-tooltip="true"  align="center"  width="70" style="width: 50px"/>
			<el-table-column label="现进价" prop="precio" :show-overflow-tooltip="true"  align="center" >
				<template slot-scope="scope">
					<span v-if="scope.row.id != ''">
						<span v-if="scope.row.precio*shezhichajia > scope.row.precioCoste" style="color:red">{{ scope.row.precio }}</span>
						<span v-if="scope.row.precio*shezhichajia < scope.row.precioCoste" style="color:green">{{ scope.row.precio }}</span>
						<span v-if="scope.row.precio*shezhichajia == scope.row.precioCoste">{{ scope.row.precio }}</span>
					</span>
					<span v-if="scope.row.id == ''">
						<el-input :id="'sysJinjiaInput_' + scope.$index" @keyup.enter.native="handleQueryBianHaoXX4(scope.$index)" v-model="scope.row.precio" placeholder="请输入"></el-input>
					</span> 
				</template>
			</el-table-column>
			<el-table-column label="原售价" prop="precioDetalle" :show-overflow-tooltip="true"  align="center" width="70" style="width: 50px" />
			<el-table-column label="现售价" prop="iVA" :show-overflow-tooltip="true"  align="center" >
				<template slot-scope="scope">
					<span v-if="scope.row.iVA*shezhichajia > scope.row.precioDetalle" style="color:red">
						<el-input  @blur="handlerEditPerice(this,scope.row)"  type="text"  v-model="scope.row.iVA" class="cell-input" 
						style="text-align: center;color: red !important;background-color: #ff6363;border-radius: 9px;"></el-input>
					</span>
					<span v-if="scope.row.iVA*shezhichajia < scope.row.precioDetalle" style="color:green">
						<el-input  @blur="handlerEditPerice(this,scope.row)"  type="text"  v-model="scope.row.iVA" class="cell-input"
						style="text-align: center;color: red !important;background-color: rgb(175 255 72);border-radius: 9px;"></el-input>
					</span>
					<span v-if="scope.row.iVA*shezhichajia == scope.row.precioDetalle" >
						<el-input  @blur="handlerEditPerice(this,scope.row)"  type="text"  v-model="scope.row.iVA" class="cell-input"
						style="text-align: center;color: red !important;border-radius: 9px;"></el-input></span>
					<span v-if="scope.row.id == ''">
						<el-input :id="'sysShoujiaInput_' + scope.$index" @keyup.enter.native="handleQueryBianHaoXX5(scope.$index)" v-model="scope.row.iVA" placeholder="请输入"></el-input>
					</span>
				</template>
			</el-table-column>
			<el-table-column label="数量" prop="cantidad" :show-overflow-tooltip="true"  align="center" width="70" style="width: 50px" >
				<template slot-scope="scope">
					{{ scope.row.cantidad }}
					<!-- <span v-if="scope.row.id == ''">
						<el-input v-model="scope.row.cantidad" placeholder="请输入"></el-input>
					</span> -->
				</template>
			</el-table-column>
			<el-table-column label="现有" prop="comentario" :show-overflow-tooltip="true" width="95" align="center" >
				<template slot-scope="scope">
					<span v-if="scope.row.id != ''">{{ scope.row.comentario }}</span>
					<span v-if="scope.row.id == ''">
						<el-input v-model="scope.row.comentario" :id="'sysShuliangInput_' + scope.$index" placeholder="请输入"></el-input>
					</span>
				</template>	
			</el-table-column>
			<el-table-column label="差数" prop="difference" :show-overflow-tooltip="true"  align="center" width="70" style="width: 50px"  />
			<el-table-column label="数量填充" prop="temporal" :show-overflow-tooltip="true"  align="center" >
				<template slot-scope="scope">
					<span v-if="scope.row.id != ''">
						<el-input :id="'sysOrderInput_' + scope.$index"  @keyup.enter.native="handlerChange(this,scope.row)"  @blur="handlerChange(this,scope.row)"  type="text"  v-model="scope.row.temporal" class="cell-input" style="text-align: center;"></el-input>
					</span>
					<span v-if="scope.row.id == ''">
					</span>
				</template>
			</el-table-column>
			<el-table-column  label="操作"  align="center" class-name="small-padding fixed-width">
		        <template slot-scope="scope">
					<span v-if="scope.row.id != ''">
						<!-- <el-button type="text" icon="el-icon-edit"  @click="handleDeletecunzainow(scope.$index, scope.row)">矫正</el-button> -->
						<el-button type="text" icon="el-icon-delete"  @click="handleJiaoZheng(scope.$index, scope.row)">删除</el-button>
					</span>
					<span v-if="scope.row.id == ''">
						<el-button type="text" icon="el-icon"  @click="handleDeletinsertList(scope.row)">确定</el-button>
						<el-button type="text" icon="el-icon"  @click="handleDeleteyiyouduihuo(scope.$index, scope.row)">删除</el-button>
					</span>
				</template>
			</el-table-column>
		</el-table>
		
		<pagination v-show="total2>0" :total="total2" :page.sync="queryParams2.pageNum" :limit.sync="queryParams2.pageSize" @pagination="getwleow1" />
	</el-dialog>
</div>
</template>
<style rel="stylesheet/scss" lang="scss" scoped>
    $border-focus-color:#A7D5EC;
    .cell-input { width: 100%; height: 100%; border: 0; top: 0;
        left: 0; width: 100%; height: 100%; padding-left: 10px;
        padding-right: 10px; box-sizing: border-box; text-align: center;
        &:focus {
            border: 1px solid $border-focus-color;
        }
    }
</style>
<script>
import {delcunzainow,getShangpinone,updateGys,getDuiHuoAll,updatesEidtPerice,getQueHuo,addIWLEO1wei,updateshuliang,importPhone,updateShezhi,getShezhi,getStyle1,getStyle2, listAlbaranproveedor,getAlbaranproveedor,updateAlbaranproveedor,addAlbaranproveedor,delAlbaranproveedor,getTypeone,getTypetwo,updateAudit,listGetDuihuo} from "@/api/goods/albaranproveedor";
export default {
  name: "Role",
  dicts: ['sys_normal_disable'],
  data() {
    return {
	  dataListpush: [],
      loading: true,
      ids: [],
      single: true,
      multiple: true,
      showSearch: true,
	  openDataQuehuo: false,
	  openDataDuiHuo: false,
	  openDataScopeShanChu: false,
      total: 0,
	  total2 : 0,
      roleList: [],
	  roleList33:[],
	  stgj: [
		{ label: '已审核', value: '1' },
		{ label: '未审核', value: '0' }
	  ],
	  selectedValue: 'value1',
	  isupxiaoshou: [
	  	{value: '1' ,label: '是' },
	  	{ value: '2', label: '否' }
	  ],
	  ischashu: [
	  	{ label: '全部', value: '1' },
	  	{ label: '负差数', value: '2' },
		{ label: '零差数', value: '3' },
		{ label: '正差数', value: '4' }
	  ],
	  typeone: [],
	  typetwo: [],
	  style1 :[],
	  style2 : [],
	  shezhighs : "",
	  shezhitype : 0,
	  shezhinum : 0,
	  shezhilastnum : 0,
	  shezhichajia : 0,
	  shezhiisupdate : 0,
      title: "",
      open: false,
      openDataScope: false,
	  openshezhi:false,
	  openDataDingdan:false,
      menuExpand: false,
      menuNodeAll: false,
      deptExpand: true,
      deptNodeAll: false,
      dateRange: [],
      menuOptions: [],
      deptOptions: [],
	  selectdingdanid:'',
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roleName: undefined,
        roleKey: undefined,
        status: undefined
      },
	  queryParams2: {
	    pageNum: 1,
	    pageSize: 10,
		configId: ""
	  },
      form: {},
      defaultProps: {
        children: "children",
        label: "label"
      }
    };
  },
  created() {
    this.getList();
	this.getShezhiss();
	this.getDeptList1();
	this.getDeptList2();
	this.getDeptList3();
	this.getDeptList4();
  },
  mounted() {
	window.addEventListener('keyup', this.handleKeyUp);
  },
  beforeDestroy() {
	window.removeEventListener('keyup', this.handleKeyUp);
  },
  methods: {
	handleJiaoZheng(){
		
		
	},
	getInputFocus() {
		  this.$nextTick(() => {
		         const input = this.$refs.queryParams.AlbaranProveedorNo.$refs.input;
		         input.select();
		       });
	    },
		  
	convertToChinese(number) {
		const chineseNumbers = ['是', '否'];
		return chineseNumbers[number - 1];
	},
	handleKeyUp(event) {
		if (event.key === 'F9') {
			if(this.openDataDingdan == true){
				this.handleAddyiyoushuju();
			}else if(this.open == true){
				this.handleAddwwd();
			}
		}
	},
	handlerBianma(index,row){
		getShangpinone(row.articuloID).then(response =>{
			row.precio = response.data.precioCoste;
			row.nombreES = response.data.nombreES;
			row.codigoBarra = response.data.codigoBarra;
			row.iVA = response.data.precioDetalle;
			
			document.getElementById("sysTiaomaInput_"+index).value = response.data.codigoBarra;
			document.getElementById("sysJinjiaInput_"+index).value = response.data.precioCoste;
			document.getElementById("sysMingchengInput_"+index).value = response.data.nombreES;
			document.getElementById("sysShoujiaInput_"+index).value = response.data.precioDetalle;
		
			//$("#sysMingchengInput_"+index).val("abc");
		})
	},
	handlerBianmaTianJia(index,row){
		getShangpinone(row.articuloID).then(response =>{
			if(!response.data){
				row.nombreES = 'AIRTICULO'
				document.getElementById("sysMingchengInput_xx"+index).value = 'AIRTICULO';
			}
			row.precio = response.data.precioCoste;
			row.nombreES = response.data.nombreES;
			row.codigoBarra = response.data.codigoBarra;
			row.iVA = response.data.precioDetalle;
			
			document.getElementById("sysTiaomaInput_xx"+index).value = response.data.codigoBarra;
			document.getElementById("sysJinjiaInput_xx"+index).value = response.data.precioCoste;
			document.getElementById("sysMingchengInput_xx"+index).value = response.data.nombreES;
			document.getElementById("sysShoujiaInput_xx"+index).value = response.data.precioDetalle;
			
			//$("#sysMingchengInput_"+index).val("abc");
		})
	},
	handlerChange(e,row) {
		this.queryParams2.articuloID = '';
		updateshuliang(row).then(response => {
			this.$modal.msgSuccess("编辑成功");
			this.getwleow1();
			document.getElementById(`sysshangpinbianma`).focus();
		});
	},
	
	handleQueryBianHao(index){
		document.getElementById(`sysTiaomaInput_xx`+index).focus();
	},
	
	handleQueryTiaoMa(index){
		document.getElementById(`sysMingchengInput_xx`+index).focus();
	},
	
	handleQueryMingCheng(index){
		document.getElementById(`sysJinjiaInput_xx`+index).focus();
	},
	
	handleQueryJinJia(index){
		var jinjianum = document.getElementById(`sysJinjiaInput_xx`+index).value;
		
		var jinjiajisuan = jinjianum * this.shezhinum;
		
		var baoliunum = jinjiajisuan.toFixed(2);
		
		var qudiaonum = baoliunum.slice(0, -1);
		
		var jisuanchajia = 0.01 * this.shezhilastnum;
		  
		var zuihjisuan = (qudiaonum * 100 + jisuanchajia * 100) / 100;
		var nowvalnum = document.getElementById(`sysShoujiaInput_xx`+index).value;
		if(nowvalnum == ''){
			document.getElementById(`sysShoujiaInput_xx`+index).value = zuihjisuan;
			this.dataListpush[index].iVA=zuihjisuan;
		}
		document.getElementById(`sysShoujiaInput_xx`+index).focus();
	},
	
	handleQueryShouJia(index){
		document.getElementById(`sysShuliangInput_xx`+index).focus();
	},
	
	handleQueryBianHaoXX1(index){
		document.getElementById(`sysTiaomaInput_`+index).focus();
	},
	
	handleQueryBianHaoXX2(index){
		document.getElementById(`sysMingchengInput_`+index).focus();
	},
	
	handleQueryBianHaoXX3(index){
		document.getElementById(`sysJinjiaInput_`+index).focus();
	},
	
	handleQueryBianHaoXX4(index){
		document.getElementById(`sysShoujiaInput_`+index).focus();
	},
	
	handleQueryBianHaoXX5(index){
		document.getElementById(`sysShuliangInput_`+index).focus();
	},
	
	handlerEditPerice(e,row){
		updatesEidtPerice(row).then(response => {
			this.$modal.msgSuccess("编辑成功");
			this.getwleow1();
		}); 
	},
	
	handleQueryShuLiang(index){
		var nexttianjia = index + 1;
		var nowvalnum = document.getElementById(`sysBianmaInput_xx`+index).value;
		var nownext = nowvalnum * 1 + 1;
		
		this.handleAddwwd();
		setTimeout(function() {
			document.getElementById(`sysBianmaInput_xx`+nexttianjia).focus();
		}, 500);
	},
	
	searchSelect(val){
		updateGys(val).then(response => {
			this.$modal.msgSuccess("编辑成功");
			this.shezhighs = val;
		}); 
	},
	
	handleAddwwd() {
		let list31 = {
			articuloID: '',
			descuento: '',
			descuentoDirecto: '',
			reglaIVA: '',
			iVASerieID: '',
			precioUsado : '',
			iVA : ''
		};
		this.dataListpush.push(list31);
	},
	
	handleAddyiyoushuju() {
		let list31 = {
			id:'',
			articuloID:'',
			descuento: '',
			descuentoDirecto: '',
			reglaIVA: '',
			iVASerieID: '',
			precioUsado : ''
		};
		this.roleList33.push(list31);
	},
	
	handleDeletewpq(index, row) {
		var _this = this
		_this.dataListpush.splice(index, 1)
	},
	
	handleDeleteyiyouduihuo(index, row) {
		var _this = this
		_this.roleList33.splice(index, 1)
	},
	handleQueHuo(){
		/* getQueHuo(this.selectdingdanid).then(response => {
			this.$modal.msgSuccess("操作成功");
			this.getwleow1();
		}); */
		this.$confirm(
			'是否进行缺货反冲（缺货反冲后，现有与数量将进行同步）？', // 第一个参数为弹窗消息内容
			'提示', // 第二个参数为弹窗左上角标题title
			{ 
			  confirmButtonText: '确定',  // 确认按钮的文本，可省略，默认为确定
			  cancelButtonText: '取消',  // 取消按钮的文本，可省略，默认为取消
			  type: 'warning' // 弹窗的消息类型，比如为warning时弹窗左边图标为'!'感叹号，为success时图标为'√'的勾。
			}).then(() => {
			  getQueHuo(this.selectdingdanid).then(response => {
			  	this.$modal.msgSuccess("操作成功");
			  	this.getwleow1();
			  });
			}).catch(() => {
			  //this.$message.info(this.$t("lang.Deletecancelled")); // 使用i18n国际化表示的“已取消删除”
			});
		
	/* 	this.$modal.confirm('是否确认删除编号为"' + roleIds + '"的数据项？').then(function() {			return getQueHuo(this.selectdingdanid);		}).then(() => {			this.$modal.msgSuccess("操作成功");
			this.getwleow1();		}).catch(() => {}); */
	},
    getList() {
		this.loading = true;
		listAlbaranproveedor(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
			this.roleList = response.rows;
			this.total = response.total;
			this.loading = false;
        });
    },
	getDeptList1(){
		getTypeone().then(response =>{
			this.typeone = response.rows;
		})
	},
	getDeptList2(){
		getTypetwo().then(response =>{
			this.typetwo = response.rows;
		})
	},
	
	getDeptList3(){
		getStyle1().then(response =>{
			this.style1 = response.rows;
		})
	},
		
	getDeptList4(){
		getStyle2().then(response =>{
			this.style2 = response.rows;
		})
	},
	
	importPhone(event) {
		const formData = new FormData();
		formData.append("file", event.raw);
		importPhone(formData).then(response => {
			this.$modal.msgSuccess("导入成功");
			this.getList();
		});
	},
		
    cancel() {
		this.open = false;
		this.reset();
    },
	
    cancelDataScope() {
		this.openDataScope = false;
		this.reset();
    },
	cancelDataScopeShanChu() {
		this.openDataScopeShanChu = false;
		this.reset();
	},
	
	cancelshezhi() {
		this.openshezhi = false;
		this.reset();
	},
    // 表单重置
    reset() {
		if (this.$refs.menu != undefined) {
			this.$refs.menu.setCheckedKeys([]);
		}
		this.resetForm("form");
    },
	
    handleQuery() {
		this.queryParams.pageNum = 1;
		this.getList();
    },
	
	handleQuery1122() {
		this.queryParams2.pageNum = 1;
		this.getwleow1();
		//this.$refs.searchInput.focus();
		
		this.$nextTick(() => {
			// 滚动到输入框
			//this.$refs.searchInput.$el.scrollIntoView({ behavior: 'smooth' });
			document.getElementById(`sysOrderInput_`+0).focus();
		});
		
	},
    /** 重置按钮操作 */
    resetQuery() {
		this.dateRange = [];
		this.resetForm("queryForm");
		this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
		this.ids = selection.map(item => item.id)
		this.single = selection.length!=1
		this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
		this.open = true;
		this.title = "添加信息";
    },
	handleduihuo(row){
		if(row.bloqueado == 1){
			this.openDataQuehuo = true;
			this.openDataDuiHuo = false;
		}else{
			this.openDataQuehuo = false;
			this.openDataDuiHuo = true;
		}
		this.reset();
		const roleId = row.id || this.ids
		this.selectdingdanid = row.albaranProveedorNo;
		this.queryParams2.configId = row.albaranProveedorNo;
		listGetDuihuo(this.queryParams2,row.albaranProveedorNo).then(response => {
		    this.roleList33 = response.rows;
			this.total2 = response.total;
		  }
		); 
		getAlbaranproveedor(roleId).then(response => {
			this.form = response.data;
			this.openDataDingdan = true;
			this.$nextTick(() => {
				roleMenu.then(res => {
				let checkedKeys = res.checkedKeys
				checkedKeys.forEach((v) => {
					this.$nextTick(()=>{
		            this.$refs.menu.setChecked(v, true ,false);
		        })
				})
		    });
			});
			this.title = "供应商：" + this.shezhighs + "      订单号："+row.albaranProveedorNo+ "      总价："+row.total;
		});
	},
	getwleow1(){
		this.queryParams2.configId = this.selectdingdanid;
		listGetDuihuo(this.queryParams2,this.selectdingdanid).then(response => {
			this.roleList33 = response.rows;
			this.total2 = response.total;
		}); 
	},
	
	handleAudit(row) {
		this.reset();
		const roleId = row.id || this.ids
		getAlbaranproveedor(roleId).then(response => {
			this.form = response.data;
			this.openDataScope = true;
			this.$nextTick(() => {
				roleMenu.then(res => {
				let checkedKeys = res.checkedKeys
				checkedKeys.forEach((v) => {
					this.$nextTick(()=>{
						this.$refs.menu.setChecked(v, true ,false);
					})
				})
			  });
			});
			this.title = "审核信息";
		});
	},
	
	getShezhiss(){
		getShezhi().then(response =>{
			this.shezhighs = response.data.ghs;
			this.shezhitype = response.data.type;
			this.shezhinum = response.data.num;
			this.shezhilastnum = response.data.lastnum;
			this.shezhichajia = response.data.zhek;
			this.shezhiisupdate = response.data.isupdate;
			if(response.data.isupdate ==1){
				this.selectedValue = "是"
			}else{
				this.selectedValue = "否"
			}
		})
	},
	
	handleShezhi() {
		this.reset();
		getShezhi().then(response => {
			this.form = response.data;
			this.openshezhi = true;
			this.$nextTick(() => {
				roleMenu.then(res => {
				let checkedKeys = res.checkedKeys
				checkedKeys.forEach((v) => {
					this.$nextTick(()=>{
						this.$refs.menu.setChecked(v, true ,false);
					})
				})
				});
			});
			this.title = "设置信息";
		});
	},
	
	submitShezhi: function() {
			
		if(this.selectedValue == 1 || this.selectedValue ==2){
			this.form.isupdate = this.selectedValue;
		}
		
	  this.$refs["form"].validate(valid => {
	    if (valid) {
			if (this.form.id != undefined) {
				updateShezhi(this.form).then(response => {
					this.$modal.msgSuccess("设置成功");
					this.openshezhi = false;
					this.getShezhiss();
				});
			}
	    }
		});
	},
	
    handleUpdate(row) {
		this.reset();
		const roleId = row.id || this.ids
		getAlbaranproveedor(roleId).then(response => {
			this.form = response.data;
			this.open = true;
			this.$nextTick(() => {
			roleMenu.then(res => {
				let checkedKeys = res.checkedKeys
				checkedKeys.forEach((v) => {
				this.$nextTick(()=>{
                    this.$refs.menu.setChecked(v, true ,false);
                })
            })
			});
        });
        this.title = "修改信息";
		});
    },
	
	handleDuihuoAll(){
		this.$confirm(
			'是否进行一键对货（一键对货后，数量与现有将进行同步）？', // 第一个参数为弹窗消息内容
			'提示', // 第二个参数为弹窗左上角标题title
			{ 
			  confirmButtonText: '确定',  // 确认按钮的文本，可省略，默认为确定
			  cancelButtonText: '取消',  // 取消按钮的文本，可省略，默认为取消
			  type: 'warning' // 弹窗的消息类型，比如为warning时弹窗左边图标为'!'感叹号，为success时图标为'√'的勾。
			}).then(() => {
			  getDuiHuoAll(this.selectdingdanid).then(response => {
			  	this.$modal.msgSuccess("操作成功");
			  	this.getwleow1();
			  });
			}).catch(() => {
			  //this.$message.info(this.$t("lang.Deletecancelled")); // 使用i18n国际化表示的“已取消删除”
			});
	},
	
	handleDeletinsertList(row){
		row.albaranProveedorNo = this.selectdingdanid;
		addIWLEO1wei(row,this.selectdingdanid).then(response => {
			this.$modal.msgSuccess("添加成功");
			this.getwleow1();
		});
	},
	
	handleDeletecunzainow(index,row){
		this.$modal.confirm('是否确认该进货信息吗？').then(function() {
		  return delcunzainow(row.id);
		}).then(() => {
		  this.getwleow1();
		  this.$modal.msgSuccess("删除成功");
		}).catch(() => {});
	},

    submitForm: function() {
		addAlbaranproveedor(this.dataListpush).then(response => {
			this.$modal.msgSuccess("提交成功");
			this.open = false;
			this.getList();
			this.dataListpush = [];
		});
    },
	
	submitDataScope: function() {
	  this.$refs["form"].validate(valid => {
	    if (valid) {
	      if (this.form.shenhedaima == '1688') {
	        updateAudit(this.form).then(response => {
	          this.$modal.msgSuccess("审核成功");
	          this.openDataScope = false;
	          this.getList();
	        });
	      }else{
			  this.$message({
				message: '代码输入错误',
				type: 'warning'
			  });
		  }
	    }
	  });
	},
	
	submitDataScopeShanChu: function() {
	  this.$refs["form"].validate(valid => {
	    if (valid) {
	      if (this.form.shanchudaima == '1688') {
	        delAlbaranproveedor(this.form.id).then(response => {
	          this.$modal.msgSuccess("删除成功");
	          this.openDataScopeShanChu = false;
	          this.getList();
	        });
	      }else{
			  this.$message({
				message: '代码输入错误',
				type: 'warning'
			  });
		  }
	    }
	  });
	},
	
	handleshanchu(row){
		this.reset();
		const roleId = row.id || this.ids
		getAlbaranproveedor(roleId).then(response => {
			this.form = response.data;
			this.openDataScopeShanChu = true;
			this.$nextTick(() => {
				roleMenu.then(res => {
				let checkedKeys = res.checkedKeys
				checkedKeys.forEach((v) => {
					this.$nextTick(()=>{
						this.$refs.menu.setChecked(v, true ,false);
					})
				})
			  });
			});
			this.title = "删除信息";
		});
		
/* 		const roleIds = row.id || this.ids;
		this.$modal.confirm('是否确认该进货信息吗？').then(function() {
		  return delAlbaranproveedor(roleIds);
		}).then(() => {
		  this.getList();
		  this.$modal.msgSuccess("删除成功");
		}).catch(() => {}); */
	},
	
    handleDelete(row) {
      const roleIds = row.id || this.ids;
      this.$modal.confirm('是否确认删除编号为"' + roleIds + '"的数据项？').then(function() {
        return delAlbaranproveedor(roleIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
	
    handleExport() {
      this.download('/goods/albaranproveedor/export?dingdanhao='+this.selectdingdanid, {}, 
	  `缺货商品信息_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>